import React, { Component } from 'react'

//componentWillUnmount

class Demo extends Component {
  render() {
    return <h1>Demo组件</h1>
  }
  componentDidMount() {
    this.timer = setInterval(()=>{
      console.log(1)
    }, 1000)
  }
  componentWillUnmount() {
    console.log('Demo组件卸载了')
    clearInterval(this.timer)
  }
}

export default class App extends Component {
  state = {
    show: true
  }
  handleClick = ()=> {
    this.setState({
      show: false
    })
  }
  render() {
    return (
      <div>
        {this.state.show ? <Demo></Demo> : ''}
        <button onClick={this.handleClick}>卸载组件</button>
      </div>
    )
  }
}
